<?php
class GoodsModel extends ViewModel{
    //定义表名
    public $table = 'goods';
    //多表关联
    public $view = array(
        'goods'=>array(
            '_type'=>'INNER',
        ),
        'catetype'=>array(
            '_on'=>'goods.cid = catetype.cid'
        ),
    );

    //表单验证
    public $validate = array(
        //商品名验证
        array('ocont','nonull','商品名不能为空',1,3),
        //所属分类
        array('cate','nonull','所属分类不能为空',1,3),
        //vip1
        array('v1m','nonull','vip1价格不能为空',1,3),
        array('v1m','regexp:/^[0-9]*+[.]{0,1}+[0-9]{0,2}$/','vip1价格错误',1,3),
        //vip2
        array('v2m','nonull','vip2价格不能为空',1,3),
        array('v2m','regexp:/^[0-9]*+[.]{0,1}+[0-9]{0,2}$/','vip2价格错误',1,3),
        //推荐价格
        array('money','nonull','推荐价格不能为空',1,3),
        array('money','regexp:/^[0-9]*+[.]{0,1}+[0-9]{0,2}$/','推荐价格错误',1,3),
        //商品备注
    );

    //查询商品列表
    public function glist($where = ''){
        return $this -> where($where) -> all();
    }
    //查询单个商品的详情
    public function gone($where = ''){
        return $this -> where($where) -> find();
    }
    //添加查询
    public function addgoods($data){
        return $this -> add($data);
    }
    //修改
    public function upgoods($where,$data){
        return $this -> where($where) -> save($data);
    }
    //删除类型
    public function goodsdel($where){
        return $this -> where($where) -> del();
    }
}